package com.javasm.crm.controller.repository;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.domin.criteria.repositrory.DefectiveCriteria;
import com.javasm.crm.domin.entity.repository.Defective;
import com.javasm.crm.service.repository.IDefectiveService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lirui
 * @since 2021-07-13
 */
@RestController
@RequestMapping("/crm/defective")
public class DefectiveController {
    @Resource
    private IDefectiveService defectiveService;

    @GetMapping("getGoods")
    @ApiOperation(value = "获取残次品库商品列表", notes = "条件、分页")
    public AxiosResult getGoods(DefectiveCriteria defectiveCriteria) {

        Integer currentPage = defectiveCriteria.getCurrentPage();
        Integer pageSize = defectiveCriteria.getPageSize();

        QueryWrapper<Defective> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<Defective> lambda = wrapper.lambda();

        //商品名称
        String goodName = defectiveCriteria.getGoodName();
        if (goodName != null && !"".equals(goodName)) {
            lambda.like(Defective::getGoodName, goodName);
        }

        //商品串号
        String goodImei = defectiveCriteria.getGoodImei();
        if (goodImei != null && !"".equals(goodImei)) {
            lambda.like(Defective::getGoodImei, goodImei);
        }

        //商品品牌
        String goodBrand = defectiveCriteria.getGoodBrand();
        if (goodBrand != null && !"".equals(goodBrand)) {
            lambda.like(Defective::getGoodBrand, goodBrand);
        }

        //商品型号
        String goodModel = defectiveCriteria.getGoodModel();
        if (goodImei != null && !"".equals(goodModel)) {
            lambda.like(Defective::getGoodModel, goodModel);
        }

        //商品状态，在库中
        lambda.eq(Defective::getGoodStatus, 0);

        Page<Defective> page = new Page<>(currentPage, pageSize);
        defectiveService.page(page, wrapper);

        return AxiosResult.success(page);
    }
}
